package com.bao.work.work01;

/**
 * @author baoye
 * @date 2024-08-08/19:13
 */
public class Printer {
    private Integer index=1;

    public Printer(Integer index) {
        this.index = index;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public Printer() {
    }
    public synchronized void print(int i){

        while(index%3==0){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.print(i);
        notifyAll();
        index++;
    }
    public synchronized void print(char c){
        while(index%3!=0){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.print(c);
        notifyAll();
        index++;
    }
}
